import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/service/familyservice.dart';

class FamilyInfomodel with ChangeNotifier {
  List<FamilyItemmodel> familylist = [];

  var longitude = 102.74133;

  Future<void> init() async {
    var result = await Familyservice.getFamilyLisst();
    familylist = FamilyListmodel.fromJson(result).list;
    print(familylist.length);
    notifyListeners();
  }

  void updatelocation(){
    longitude += 0.00001;
    familylist[0].position = 'longitude:$longitude;latitude:25.0675;';
    print('object');
    notifyListeners();
  }
}

class FamilyListmodel {
  final List<FamilyItemmodel> list;

  FamilyListmodel(this.list);

  factory FamilyListmodel.fromJson(List<dynamic> itemlist) {
    return FamilyListmodel(
      itemlist.map((item) => FamilyItemmodel.fromJson(item)).toList(),
    );
  }
}

class FamilyItemmodel {
  int id;
  int userId;
  int relationId;
  int logoId;
  String personName;
  String personBirth;
  int personSex;
  double height;
  double weight;
  int rateNow;
  String position;
  double temp;
  int steps;
  double blood;
  int watchId;
  double safeDistance;

  FamilyItemmodel({
    this.id,
    this.userId,
    this.relationId,
    this.logoId,
    this.personName,
    this.personBirth,
    this.personSex,
    this.height,
    this.weight,
    this.blood,
    this.position,
    this.rateNow,
    this.safeDistance,
    this.steps,
    this.temp,
    this.watchId,
  });

  factory FamilyItemmodel.fromJson(dynamic item) {
    return FamilyItemmodel(
      id: item['id'],
      userId: item['userId'],
      relationId: item['relationId'],
      logoId: item['logoId'],
      personName: item['personName'],
      personBirth: item['personBirth'],
      personSex: item['personSex'],
      height: item['height'],
      blood: item['blood'],
      position: item['position'],
      rateNow: item['rateNow'],
      safeDistance: item['safeDistance'],
      steps: item['steps'],
      temp: item['temp'],
      watchId: item['watchId'],
    );
  }
}
